self.domains_lock.release()
+ def domain_create_from_dict(self, config_dict):
+ """Create a domain from a configuration dictionary.
+
+ @param config_dict: configuration
+ @rtype: XendDomainInfo
+ """
+ self.domains_lock.acquire()
+ try:
+ self._refresh()
+
+ dominfo = XendDomainInfo.create_from_dict(config_dict)
+ self._add_domain(dominfo)
+ self.domain_sched_credit_set(dominfo.getDomid(),
+ dominfo.getWeight(),
+ dominfo.getCap())
+ return dominfo
+ finally:
+ self.domains_lock.release()
+
+
def domain_new(self, config):
"""Create a domain from a configuration but do not start it.
def create(config):
"""Creates and start a VM using the supplied configuration.
- (called from XMLRPCServer directly)
@param config: A configuration object involving lists of tuples.
@type config: list of lists, eg ['vm', ['image', 'xen.gz']]
@rtype: XendDomainInfo
- @return: A up and running XendDomainInfo instance
+ @return: An up and running XendDomainInfo instance
@raise VmError: Invalid configuration or failure to start.
"""
return vm
+def create_from_dict(config_dict):
+ """Creates and start a VM using the supplied configuration.
+
+ @param config_dict: An configuration dictionary.
+
+ @rtype: XendDomainInfo
+ @return: An up and running XendDomainInfo instance
+ @raise VmError: Invalid configuration or failure to start.
+ """
+
+ log.debug("XendDomainInfo.create_from_dict(%s)",
+ scrub_password(config_dict))
+ vm = XendDomainInfo(XendConfig.XendConfig(xapi = config_dict))
+ try:
+ vm.start()
+ except:
+ log.exception('Domain construction failed')
+ vm.destroy()
+ raise
+
+ return vm
+
def recreate(info, priv):
"""Create the VM object for an existing domain. The domain must not
be dying, as the paths in the store should already have been removed,
"""
from xen.xend import XendDomain
- config = self.sxpr()
-
- if self._infoIsSet('cpus') and len(self.info['cpus']) != 0:
- config.append(['cpus', reduce(lambda x, y: str(x) + "," + str(y),
- self.info['cpus'])])
-
if self._readVm(RESTART_IN_PROGRESS):
log.error('Xend failed during restart of domain %s. '
'Refusing to restart to avoid loops.',
new_dom = None
try:
- new_dom = XendDomain.instance().domain_create(config)
+ new_dom = XendDomain.instance().domain_create_from_dict(
+ self.info)
new_dom.unpause()
rst_cnt = self._readVm('xend/restart_count')
rst_cnt = int(rst_cnt) + 1